# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午4:20
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : contract_add_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class  ContractAddPage(BasePage):
    """添加合同页面"""
    url="/crm/index.php?m=contract&a=add"
    business_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[3]/td[2]/input[2]")  # 商机来源
    business_circle_locator = (By.XPATH, "/html/body/div[7]/div[2]/table/tbody[2]/tr/td[1]/input[1]")  # 勾选商机
    business_ok_locator = (By.XPATH, "/html/body/div[7]/div[3]/div/button[1]/span")  # 点击OK
    condition_locator = (By.CSS_SELECTOR, "body")  # 条件和条款输入框
    save_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")  # 点击保存

    def click_business(self):
        """点击商机来源框"""
        self.driver.find_element(*self.business_locator).click()
    def click_business_circle(self):
        """选择商机"""
        self.driver.find_element(*self.business_circle_locator).click()
    def click_business_ok(self):
        """点击OK"""
        self.driver.find_element(*self.business_ok_locator).click()
    def switch_default_frame(self):
        """切换到最外层frame"""
        self.driver.switch_to.default_content()
    def switch_own_frame(self):
        """切换到自己所在的frame"""
        self.driver.switch_to.frame(0)

    def input_condition(self,condition):
         """输入条件和条款"""
         self.driver.find_element(*self.condition_locator).send_keys(condition)
    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.save_locator).click()


